package com.gz.controller;


import com.github.abel533.echarts.Title;
import com.github.abel533.echarts.axis.Axis;
import com.github.abel533.echarts.axis.CategoryAxis;
import com.github.abel533.echarts.axis.ValueAxis;
import com.github.abel533.echarts.code.Trigger;
import com.github.abel533.echarts.json.GsonOption;
import com.github.abel533.echarts.series.Bar;
import com.github.abel533.echarts.series.Line;
import com.gz.entity.PageCount;
import com.gz.mapper.EchartsMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.logging.SimpleFormatter;

@Controller
public class EchartsController {
    
    @Autowired
    EchartsMapper echartsMapper;

    @RequestMapping("showPvBar")
    public String showPv(){
        return "pv";
    }
    
    @RequestMapping("showPvLine")
    public String showPvLine(){
        return "pv";
    }


@RequestMapping("ajaxPvBar")
@ResponseBody
public String ajaxPvBar(){
    
    GsonOption option = new GsonOption();
    
    Title title = new Title();
    title.setText("站点统计");
    option.setTitle(title);
    option.tooltip().trigger(Trigger.axis);
    option.legend("站点统计");
//
//    option.toolbox().show(true);
//    option.calculable(true);
//
//    List<Axis> axes = new ArrayList<Axis>();
//    List<Axis> yaxes = new ArrayList<Axis>();
    
    CategoryAxis axis1 = new CategoryAxis();
    axis1.data("pv", "uv", "ip", "newUser");
    option.xAxis(axis1);
    
    Axis yaxes = new ValueAxis();
    option.yAxis(yaxes);
    
//    PageCount pageCount = echartsMapper.selectPv("2020-10-29");
    
    Bar line = new Bar();
    line.name("xiao");
//    line.data(pageCount.getPv(), pageCount.getUv(), pageCount.getIp(), pageCount.getNewUser());
    line.data(20, 30, 40, 50);
    option.series(line);
    
    return option.toString();

}
    
    @RequestMapping("ajaxPvLine")
    @ResponseBody
    public String ajaxPvLine(){
        
         //
        GsonOption option = new GsonOption();
        
//        Title title = new Title();
//        title.setText("站点统计");
//        option.setTitle(title);
        
//        option.tooltip().trigger(Trigger.axis);
        option.legend("aaaa");
//
        option.toolbox().show(true);
        option.calculable(true);
//
//    List<Axis> axes = new ArrayList<Axis>();
//    List<Axis> yaxes = new ArrayList<Axis>();
        
        // Axis
        CategoryAxis axis1 = new CategoryAxis();
        axis1.data("pv", "uv", "ip", "newUser");
        option.xAxis(axis1);
        
        Axis yaxes = new ValueAxis();
        option.yAxis(yaxes);
        
        PageCount pageCount = echartsMapper.selectPv("2020-10-29");
        
        Bar line = new Bar();
        line.name("xiao");
        line.data(pageCount.getPv(), pageCount.getUv(), pageCount.getIp(), pageCount.getNewUser());
        option.series(line);
        
        return option.toString();
        
    }
    
    @RequestMapping("showPv2")
    public String showPv2(){
        return "pv2";
    }
    
    
    @RequestMapping("pv2")
    @ResponseBody
    public String pv2(String time){
    
        // 2020-10-30
        Date date = new Date(System.currentTimeMillis());
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        String form = sdf.format(date);
        System.out.println(form);
        GsonOption option = new GsonOption();
    
        Axis xaxis = new CategoryAxis();
        xaxis.data("pv", "uv", "ip");
        option.xAxis(xaxis);
    
        Axis yaxis = new ValueAxis();
        option.yAxis(yaxis);
        
        PageCount pv = echartsMapper.selectPv(form);

//        Line line = new Line();
//        line.data(pv.getPv(), pv.getUv(), pv.getIp());
//        option.series(line);
        
        Bar bar = new Bar();
        bar.data(pv.getPv(), pv.getUv(), pv.getIp());
        option.series(bar);
    
        return option.toString();
        
    }
    
    
    
    
    


}
